package brian.android.mvc.event;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;

import android.util.Log;
import android.view.View;
import android.view.View.OnFocusChangeListener;

public class OnFocusChangeEventHandler extends AbstactEventHandler implements EventHandler, OnFocusChangeListener {
	@SuppressWarnings("unchecked")
	protected Class getEventListener() {
		return OnFocusChangeListener.class;
	}

	@Override
	public void onFocusChange(View view, boolean hasFocus) {
		Method eventMethod = getEventMethod();
		List<Object> argViews = getArguments(eventMethod, new Object[]{view, hasFocus}, new Class[]{view.getClass(), Boolean.class});
		try {
			eventMethod.invoke(getActivity(), argViews.toArray());
		} catch (IllegalArgumentException e) {
			Log.e(this.getClass().getSimpleName(), "Error[" + getEventMethod().getName() + "]", e);
		} catch (IllegalAccessException e) {
			Log.e(this.getClass().getSimpleName(), "Error[" + getEventMethod().getName() + "]", e);
		} catch (InvocationTargetException e) {
			Log.e(this.getClass().getSimpleName(), "Error[" + getEventMethod().getName() + "]", e);
		}
	}
}
